from settings import config
import pymongo
from pymongo import MongoClient
client = MongoClient(config['CONFIGDB_URL'])


user = [
    {"username":"zhouwei","token":"548c39abbabba11652c53cfd82cae049","group":"admin","groupname":"admin"},
    {"username":"admin","token":"50e714248e7809b3cf92065590a9695d","group":"ops","groupname":"运维"},
    {"username":"dev","token":"8d68847e023c401e8103968c8143907c","group":"dev","groupname":"开发"},
]

usergroup = [
    {"group":"admin","permission":["dev","testenv","testperf02","prod","template","global_template","salt","system"],"groupname":"admin"},
    {"group":"dev","permission":["dev","testenv","testperf02","template","global_template"],"groupname":"开发"},
    {"group":"test","permission":["dev","testenv","testperf02"],"groupname":"测试"},
    {"group":"ops","groupname":"运维","permission":["salt"]},
]

def init_data():
    db = client.config
    cnames = db.collection_names(include_system_collections=False)
    if cnames:
        print(cnames)
        print('已经初始化过了')
        return
    db.user.insert_many(user)
    db.usergroup.insert_many(usergroup)
    print('done')


if __name__ == '__main__':
    init_data()